#include <time.h>
#include <stdio.h>
#include <string.h>

#include "../t4.h"

int
main(int argc, char *argv[])
{
	T4_out out;
	T4_in in;
	T4_dat dat;
	T4_brk brk = T4_BRK_INIT;
	int error = 0;

	(void) argc;
	(void) argv;

	if (!t4_term_set()) {
		fprintf(stderr, "Could not set up terminal for t4\n");
		return 1;
	}

	if (!t4_out_init(&out, "./pipe", 0.25, 1)) {
		fprintf(stderr, "Could not initialize t4_out\n");
		return 1;
	}

	if (!t4_dat_init(&dat, "A really really sorta long string, folks!")) {
		t4_out_dispose(&out);
		fprintf(stderr, "Could not initialize t4_dat\n");
		return 1;
	}

	t4_in_init(&in, 0);

	while (1) {
		if (!t4_out(&out, &dat, &brk)) {
			error = 1;
			fprintf(stderr, "Error outputting t4_out\n");
		}

		if (brk.done)
			break;

		printf("\nStop interrupting!\n");

		if (!t4_in_empty()) {
			error = 1;
			fprintf(stderr, "Could not empty t4_in\n");
		        break;
		}
	}

	t4_dat_dispose(&dat);
	t4_out_dispose(&out);
	return error;
}
